<template>
  <div class="view-wrapper">
    <div class="head">
      <el-form :model="queryParams" ref="queryForm" :inline="true">
        <el-form-item label="管辖区域：" prop="areaId">
          <el-select v-model="queryParams.areaId" placeholder="全部" >
            <el-option v-for="item in areaSelect" :key="item.id" :label="item.value" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="活动名称：" prop="activityName">
          <el-input v-model="queryParams.activityName" placeholder="请输入" clearable />
        </el-form-item>
        <el-form-item label="店铺名称：" prop="shopName">
          <el-input v-model="queryParams.shopName" placeholder="请输入" clearable />
        </el-form-item>
        <el-form-item label="用户：" prop="customer">
          <el-input v-model="queryParams.customer" placeholder="姓名、手机号" clearable />
        </el-form-item>
        <el-form-item label="交易时间：" prop="date">
          <el-date-picker v-model="date" start-placeholder="开始日期" end-placeholder="结束日期" :clearable="false"
            type="daterange" format="yyyy-MM-dd" value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="发放状态：" prop="status">
          <el-select v-model="queryParams.status" placeholder="全部"  >
            <el-option v-for="item in statusList" :key="item.id" :label="item.value" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="listBox">
      <div class="topBtn" style="margin-bottom: 14px">
        <div>
          <export-excel-button title="消费激励明细" action="/shenye/incentive/activity/give/record/export" :params="ExportParams" />
        </div>
      </div>
      <el-table v-loading="loading" :data="customerList" stripe border>
        <el-table-column label="序号" type="index" width="55" align="center" fixed />
        <el-table-column label="管辖区域" align="center" prop="govAreaName" :show-overflow-tooltip="true" />
        <el-table-column label="活动名称" align="center" prop="activityName" :show-overflow-tooltip="true" />
        <el-table-column label="交易店铺" align="center" prop="shopName" :show-overflow-tooltip="true" />
        <el-table-column label="交易时间" align="center" prop="createTime" width="160" />
        <el-table-column label="激励规则" align="center" prop="incentiveRule" width="200" />
        <el-table-column label="姓名" align="center" prop="name" :show-overflow-tooltip="true" />
        <el-table-column label="手机号" align="center" prop="phone" :show-overflow-tooltip="true" />
        <el-table-column label="交易金额（￥）" align="center" prop="payMoney" :show-overflow-tooltip="true" />
        <el-table-column label="激励值" align="center" prop="incentiveAmount" :show-overflow-tooltip="true" />
        <el-table-column label="状态" align="center" prop="status" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <dict-tag :options="statusList" :value="scope.row.status" />
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList" />

    </div>
  </div>

</template>

<script>
  import {
    userAreaSelect,
  } from "@/api/common";
  import {
    giveRecordList,
  } from "@/api/consumeIncentiveManagement/incentiveActivities";
  import ExportExcelButton from "@/components/ExportExcelButton/index";
  export default {
    name: "Customer",
    components: {
      ExportExcelButton,
    },
    data() {
      return {
        id: '',
        pathType: 'add',
        // 遮罩层
        loading: false,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 表格数据
        customerList: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          activityName: '', //活动名称
          areaId: '', //管辖区域id
          customer: '', //用户
          endTime: '', //交易结束时间
          shopName: '', //店铺名称
          startTime: '', //交易开始时间
          status: '', //状态 1-未发放 2-已发放 3-交易撤销 shenye_incentive_give_record_status
        },
        date: [],
        areaSelect: [], //区域下拉
        statusList: [], //状态字典
      };
    },
    computed: {
      ExportParams() {
        const params = {
          ...this.queryParams,
        };
        return params;
      },
    },
    created() {
      this.getAdminDict()
      this.getUserAreaSelect();
      this.getList();
    },
    methods: {
      getUserAreaSelect() {
        //查询用户区域下拉框
        userAreaSelect().then((res) => {
          var arr = [{
            id: "",
            value: "全部",
          }, ];
          this.areaSelect = arr.concat(res.result);
        });
      },
      //获取字典
      getAdminDict() {
        var dictType = "shenye_incentive_give_record_status";
        this.$getSelectList(dictType)
          .then((res) => {
            var arr = [{
              id: "",
              value: "全部",
            }, ];
            this.statusList = arr.concat(res.result[0].dictList);
          })
          .finally(() => {
            this.loading = false;
          });
      },
      /** 查询列表 */
      getList() {
        this.loading = true;
        giveRecordList(this.queryParams).then(response => {
          this.total = response.result.total
          this.customerList = response.result.records
          this.loading = false;

        }).finally(() => {
          this.loading = false;
        })
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.startTime = this.date[0];
        this.queryParams.endTime = this.date[1];
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.date = []
        this.queryParams = {
          pageNum: 1,
          pageSize: 10,
          activityName: '', //活动名称
          areaId: '', //管辖区域id
          customer: '', //用户
          endTime: '', //交易结束时间
          shopName: '', //店铺名称
          startTime: '', //交易开始时间
          status: '', //状态 1-未发放 2-已发放 3-交易撤销 shenye_incentive_give_record_status
        }
        this.handleQuery();
      },
    }
  };

</script>
<style lang="scss" scoped>
  .head {
    box-shadow: 0px 4px 12px 0px rgb(1 41 99 / 6%);
    background-color: #fff;
    border-radius: 8px;
    padding: 20px 20px 0;

  }

  .head_st {
    display: flex;
    justify-content: flex-start;
    flex-wrap: wrap;
    box-shadow: 0px 4px 12px 0px rgb(1 41 99 / 6%);
    border-radius: 8px;
    margin-bottom: 14px;
    background: #F3F5F7;
  }

  .card_d {
    // width: 420px;
    padding: 0 0px 0 20px;
    height: 100px;
    border-radius: 10px;
    display: flex;
    justify-content: space-between;
    margin-right: 14px;
    background-color: #fff;
    margin-bottom: 10px;

    .list {
      display: flex;
      flex-direction: column;
      flex: 1;
      align-items: center;
      justify-content: center;
      margin-right: 20px;

      p:nth-child(1) {
        font-size: 20px;
        font-weight: bold;
        color: #555;

      }

      p:nth-child(2) {
        font-size: 18px;
        color: #555;
        margin-top: 20px;
      }
    }
  }

  .listBox {
    box-shadow: 0px 4px 12px 0px rgb(1 41 99 / 6%);
    background-color: #fff;
    border-radius: 8px;
    //   height: 120px;
    padding: 20px 20px;
    margin-top: 10px;
  }

  .topBtn {
    display: flex;
    justify-content: flex-start;
    align-items: center;
  }

</style>
